package top.ffhome.system.config.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * Shiro工具类
 * @author John
 *
 */
public abstract class ShiroUtil {
	/**
	 * 判断是否登录
	 * @return
	 */
	public static boolean isAuthenticated() {
		return getSubject().isAuthenticated();
	}

	/**
	 * 判断权限处理
	 * @param perms
	 * @return
	 */
	public static boolean check(String perms) {
		return getSubject().isPermitted(perms);
	}

	public static Subject getSubject() {
		return SecurityUtils.getSubject();
	}

	public static Session getSession() {
		return getSubject().getSession();
	}

	public static Object getAttribute(Object key) {
		return getSession().getAttribute(key);
	}

	public static void setAttribute(Object key, Object value) {
		getSession().setAttribute(key, value);
	}
}
